using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Text;
using NUnit.Framework;
using MeetingRoom.Domain;
using MeetingRoom.Data.Implementation;

namespace MeetingRoom.UnitTest
{
    [TestFixture]
    public class CreateScheduleTest
    {
        [Test]
        public void TestCreate()
        {
            MeetingRoomType meetingRoomType = new MeetingRoomType();
            meetingRoomType.Id = 1;
            meetingRoomType.Count = 2;
            meetingRoomType.Size = 20;

            Staff staff = new Staff();
            staff.Id = 1;

            Schedule schedule = new Schedule();
            schedule.Id = 1;
            schedule.Name = "Hello";
            schedule.Applicant = staff;
            schedule.Duration = new Duration(
                new DateTime(2007, 1, 10, 1, 0, 0), new DateTime(2007, 1, 12, 3, 0, 0));
            schedule.MeetingRoomType = meetingRoomType;
            schedule.Status = ScheduleStatus.PENDING;

            SimpleScheduleDao.Create(schedule);
        }

        [Test]
        public void TestGetMeetingRoomType()
        {
            SimpleMeetingRoomTypeQuery obj = new SimpleMeetingRoomTypeQuery();
            obj.Connection = new System.Data.SqlClient.SqlConnection(
                ConfigurationSettings.AppSettings["connectionString"]);
            MeetingRoomType meetingRoomType = new MeetingRoomType();
            meetingRoomType.Id = 1;
            meetingRoomType.Count = 2;
            meetingRoomType.Size = 20;
            meetingRoomType.Projector = false;

            MeetingRoomType[] meetingRoomTypes = null;
            try
            {
                meetingRoomTypes = obj.GetMeetingRoomTypes(meetingRoomType);
            }
            finally
            {
                obj.Connection.Close();
            }

            Assert.AreEqual(1, meetingRoomTypes.Length);
        }

        [Test]
        public void TestSimpleGetSchedulesByMeetingRoomType()
        {
            SimpleScheduleDataQuery obj =
                new SimpleScheduleDataQuery();
            obj.Connection =
                new System.Data.SqlClient.SqlConnection(
                ConfigurationSettings.AppSettings["connectionString"]);

            try
            {
                MeetingRoom.Domain.MeetingRoomType meetingRoomType = new MeetingRoomType();
                meetingRoomType.Id = 1;
                meetingRoomType.Count = 2;
                meetingRoomType.Size = 20;
                meetingRoomType.Projector = false;
                List<Schedule> schedules = obj.GetSchedulesByMeetingRoomType(meetingRoomType);

                Assert.AreEqual(2, schedules.Count);
                Assert.AreEqual(1, schedules[0].Id);
            }
            catch
            {
            }
            finally
            {
                if (obj.Connection.State == System.Data.ConnectionState.Open)
                {
                    obj.Connection.Close();
                }
            }
        }
    }
}
